package com.example.medmobile.profissional;

import WebService.SoapWebService;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.Log;

import com.example.medmobile.Global;
import com.google.appengine.medmobileserver.business.Profissional;

public class CaixaEntradaProfissionalHandler extends CaixaEntradaProfissional
		implements Runnable {
	private Context context;
	private String sData;

	protected void CarregaLista(final String sData, final Context context) {
		try {
			this.sData = sData;
			this.context = context;

				dialog = ProgressDialog.show(context, "Agendamentos",
						"Carregando agendamentos.", true, false);

			new Thread(CaixaEntradaProfissionalHandler.this).start();

		} catch (Exception e) {

			Log.i("CX", "erro carregalista");
			Log.i("CX", e.getMessage().toString());
			e.getMessage();
		}
	}

	@Override
	public void run() {
		Profissional p = Global.getProfissionalLogado();

		li = SoapWebService.BuscaAgendamentosProfissional(
				p.getIdProfissional(), sData);
		runOnUiThread(new Runnable() {
			public void run() {
				try {

					CaixaEntradaProfissionalAdapter ra = new CaixaEntradaProfissionalAdapter(
							context, li);

					listView.setAdapter(ra);
				} finally {
					Log.i("CX", "Finnaly");
					handler.post(new Runnable() {

						@Override
						public void run() {
							Log.i("CX", "dialog dismisss");
							dialog.dismiss();
							Log.i("CX", "dialog dismisss foi ");

						}
					});

				}

			}
		});

	}
}
